package org.qfedu.edu.seckill.service.impl;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import org.qfedu.edu.seckill.service.IJwtService;
import org.qfedu.edu.seckill.service.ITokenService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

public class JwtService implements IJwtService {

    @Resource
    private ITokenService tokenService;

    @Override
    public String getUserId(String token) {
        Jws<Claims> claimsJws = tokenService.parseToken(token);
        return claimsJws.getBody().getId();
    }

    @Override
    public String getUsername(String token) {
        Jws<Claims> claimsJws = tokenService.parseToken(token);
        return claimsJws.getBody().getSubject();
    }
}
